// export class Goods{
//     id:number=0
//    private name:string=''
//     description:string=''
//     price:number=0
//     quantity:number=0
//     icon:string=''
//     constructor(id:number,name:string,description:string,price:number,quantity:number,icon:string){
//         this.id = id
//         this.name = name
//         this.description = description
//         this.price = price
//         this.quantity = quantity
//         this.icon = icon
//     }
//     getGoodsName():string{
//         return this.name
//     }
// }
// export function add(x:number,y:number):number{
//     return x*y
// }
// export class Comments{
//     id:number=0
//     username:string=''
//     apprise:number=0
//     title:string=''
//     private content:string=''
//     constructor(id:number,username:string,apprise:number, title:string,content:string){
//         this.id = id
//         this.username = username 
//         this.apprise=apprise
//         this.title=title
//         this.content=content
//     }
//     showContent():string{
//         return this.content
//     }
// } 
// export function sumLikes(arr:Comments[]):number{
//     let total:number = 0//总评论数
//     for(let i of arr){
//         total+=i.apprise
//     }
//     return total
// }

interface Goods {
    id: number
    name: string
    description: string
    quantity: number
    icon: string
    price: number
}
const GoodsList: Goods[] = [
    { id: 1, name: '华为 P30 ', description: '全面屏超感光徕卡三摄变焦双景录像980芯片智能手机p30', quantity: 1, icon: '/images/01.png', price: 4288 },
    { id: 2, name: '小米 Redmi K20 Pro', description: '全面屏骁龙855超广角AI三摄9手机官方旗舰店正品cc红米k20', quantity: 1, icon: '/images/02.png', price: 2799 },
    { id: 3, name: '华为 Mate 20', description: '全面屏超大广角徕卡三镜头麒麟980人工智能芯片手机', quantity: 1, icon: '/images/03.png', price: 3299 },
    { id: 4, name: '华为Mate XT非凡大师', description: '10.2英寸超形态三折叠大屏，一机多能，华为天工铰链系统', quantity: 1, icon: '/images/04.png', price: 23999 },
]
console.log(GoodsList);
function sumCart(goodsList: Goods[]): number {
    let totalPrice = 0;
    for (const item of goodsList) {
        totalPrice += item.price * item.quantity;
    }
    return totalPrice;
}
const totalPrice = sumCart(GoodsList);
console.log(`总价是: ${totalPrice}`);
function findGoods(keyword: string): Goods[] {
    return GoodsList.filter(good => good.name.includes(keyword));
}
const result = findGoods('华为');
console.log(result);
const discount = 0.9;
function discountPrice(goodsList: Goods[], discount: number): void {
    goodsList.forEach(good => {
        const newPrice = good.price * discount;
        console.log(`商品编号: ${good.id}, 原价格: ${good.price}, 新价格: ${newPrice}`);
    });
}
function resort(goodsList: Goods[], discount: number): void {
    const sortedGoodsList = goodsList.slice().sort((a, b) => a.price - b.price);
    sortedGoodsList.forEach(good => {
        const newPrice = good.price * discount;
        console.log(`商品编号: ${good.id}, 原价格: ${good.price}, 新价格: ${newPrice}`);
    });
}

discountPrice(GoodsList, discount);
resort(GoodsList, discount);